/*
 * Composition Knowledge Miner. A data mashup composition knowledge miner
 * Copyright (C) 2011 Carlos Rodriguez
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

package eu.ict_omelette.mashup.compositionminer.util;

/**
 *
 * @author carlos
 */
public class Itemset implements Comparable {
    public int[] items;
    public boolean redundant = false;

    public Itemset(int [] items){
        this.items = items;
    }

    public int compareTo(Object o) {
        int result;
        
        if(this.items.length < ((Itemset)o).items.length)
            result = -1;
        else if(this.items.length == ((Itemset)o).items.length)
            result = 0;
        else
            result = 1;

        return result;

    }

    public boolean isSubset(Itemset subItemset){
        boolean result = true;

        int[] cSuper = this.items;
        int[] cSub = subItemset.items;

        for(int i = 0; i < cSub.length; i++){
            boolean exists = false;

            for(int j=0; j < cSuper.length; j++){

                if(cSub[i] == cSuper[j]){
                    exists = true;
                    break;
                }
                
            }

            if(!exists){
                result = false;
                break;
            }            
        }

        return result;
    }
    

}
